package com.thinkinginobjects.specification;

import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;

import com.thinkinginobjects.domainobject.Account;
import com.thinkinginobjects.repository.AccountSpecification;
import com.thinkinginobjects.repository.HibernateSpecification;


public class AccountSpecificationByUserName implements AccountSpecification, HibernateSpecification {
	
	private String desiredUserName;

	public AccountSpecificationByUserName(String desiredUserName) {
		super();
		this.desiredUserName = desiredUserName;
	}

	@Override
	public boolean specified(Account account) {
		return account.hasUseName(desiredUserName);
	}

    @Override
    public Criterion toCriteria() {
        return Restrictions.eq("userName", desiredUserName);
    }

}
